import { AfterViewInit, Component, OnInit } from '@angular/core';
import * as moment from 'moment';
import {
    DayTaskData,
    DayViewCalendar,
    DayViewOptions,
    DropDomWrapper,
} from './test';

@Component({
    selector: 'app-day-view',
    templateUrl: './day-view.component.html',
    styleUrls: ['./day-view.component.less'],
})
export class DayViewComponent implements OnInit, AfterViewInit {
    constructor() {}

    taskList: any[] = [];

    ngAfterViewInit(): void {
        const a = new DayViewCalendar(document.getElementById('test'), {
            dayStartTime: moment(moment().format('yyyy-MM-DD 08:00')).toDate(),
            dayEndTime: moment(moment().format('yyyy-MM-DD 20:00')).toDate(),
            daySpacing: 60,
            dayRangeSpacing: 10,
            dayCellHeight: 100,
            dayCellWidth: 160,
        } as unknown as DayViewOptions);
        a.render([
            {
                startTime: moment('2022-06-05 08:04').toDate(),
                endTime: moment('2022-06-05 08:20').toDate(),
                canDrop: true,
                canRemove: true,
                data: {
                    id: '1',
                    name: '饭饭不吃饭',
                    no: '00001',
                    sex: '男',
                    age: '21岁',
                    pos: '头部',
                    total: 20,
                    current: 1,
                },
            } as DayTaskData,

            {
                startTime: moment('2022-06-05 08:04').toDate(),
                endTime: moment('2022-06-05 08:20').toDate(),
                canDrop: true,
                canRemove: true,
                data: {
                    id: '1',
                    name: '饭饭不吃饭',
                    no: '00001',
                    sex: '男',
                    age: '21岁',
                    pos: '头部',
                    total: 20,
                    current: 1,
                },
            } as DayTaskData,

            {
                startTime: moment('2022-06-05 08:04').toDate(),
                endTime: moment('2022-06-05 08:20').toDate(),
                canDrop: true,
                canRemove: true,
                data: {
                    id: '1',
                    name: '饭饭不吃饭',
                    no: '00001',
                    sex: '男',
                    age: '21岁',
                    pos: '头部',
                    total: 20,
                    current: 1,
                },
            } as DayTaskData,

            {
                startTime: moment('2022-06-05 08:04').toDate(),
                endTime: moment('2022-06-05 08:20').toDate(),
                canDrop: true,
                canRemove: true,
                data: {
                    id: '1',
                    name: '饭饭不吃饭',
                    no: '00001',
                    sex: '男',
                    age: '21岁',
                    pos: '头部',
                    total: 20,
                    current: 1,
                },
            } as DayTaskData,

            {
                startTime: moment('2022-06-05 08:05').toDate(),
                endTime: moment('2022-06-05 08:20').toDate(),
                canDrop: false,
                canRemove: true,
                data: {
                    id: '2',
                    name: '饭饭吃饭',
                    no: '00002',
                    sex: '男',
                    age: '21岁',
                    pos: '头部',
                    total: 20,
                    current: 1,
                },
            } as DayTaskData,

            {
                startTime: moment('2022-06-05 09:05').toDate(),
                endTime: moment('2022-06-05 09:50').toDate(),
                canDrop: true,
                canRemove: false,
                data: {
                    id: '3',
                    name: '饭饭吃饭233',
                    no: '00002',
                    sex: '男',
                    age: '21岁',
                    pos: '头部',
                    total: 20,
                    current: 1,
                },
            } as DayTaskData,
        ]);
        for (const item of this.taskList) {
            const ele = document.getElementById(item.id);
            const wp = new DropDomWrapper(ele, a, item);
        }
    }

    ngOnInit(): void {
        this.taskList.push({
            id: '1',
            name: '饭饭不吃饭',
            no: '00001',
            sex: '男',
            age: '21岁',
            pos: '头部',
            total: 20,
            current: 1,
        });
        this.taskList.push({
            id: '2',
            name: '饭饭爱吃饭',
            no: '00002',
            sex: '男',
            age: '22岁',
            pos: '头部',
            total: 10,
            current: 2,
        });
        this.taskList.push({
            id: '3',
            name: '饭饭就吃饭',
            no: '00003',
            sex: '男',
            age: '23岁',
            pos: '头部',
            total: 10,
            current: 1,
        });
        this.taskList.push({
            id: '4',
            name: '饭饭就吃饭',
            no: '00005',
            sex: '男',
            age: '23岁',
            pos: '头部',
            total: 10,
            current: 1,
        });
        this.taskList.push({
            id: '5',
            name: '饭饭就吃饭',
            no: '00006',
            sex: '男',
            age: '23岁',
            pos: '头部',
            total: 12,
            current: 1,
        });
    }
}
